<template>
   <view>
	   <web-view :src="url" @message="handleMessage"></web-view>
   </view>
</template>
<script>
    export default {
        name: "",
        components:{
            
        },
		onLoad(options) {
			let _this = this
			this.url = this.$SysCache.get("tempURl")
			this.orderNo = options.oid
			
		},
        data(){ 
            return {
                url:'',
				orderNo:''
            }
        },
		methods:{
			handleMessage(evt){
				// console.log('接收到的消息：' + JSON.stringify(evt.detail.data));
				let that = this
				let payData =(evt.detail.data)[0]
				let paytype = ''
				if(payData.tradeType == 'aliPay'){
					paytype = 'alipay'
				}else{
					paytype = 'wxpay'
					// payData.result = this.urlEncode(JSON.parse(payData.result))
				}
				console.log(payData.result)
				
				uni.requestPayment({
				    provider: paytype,
				    orderInfo: payData.result, //微信、支付宝订单数据
				    success: function (res) {
				        console.log('success:' + JSON.stringify(res));
						uni.navigateTo({
							url: `/pages/order/success?cOrderNo=${that.orderNo}&type=1`
						})
				    },
				    fail: function (err) {
				        console.log('fail:' + JSON.stringify(err));
				    }
				});
			},
			urlEncode(param, key, encode) {
			  if(param==null) return '';
			  var paramStr = '';
			  var t = typeof (param);
			  if (t == 'string' || t == 'number' || t == 'boolean') {
			    if(key == "package"){
			    	paramStr +=  key + '=' + ((encode == null || encode) ? encodeURIComponent(param) : param);
			    }
			    else{
			    	paramStr += '&' + key + '=' + ((encode == null || encode) ? encodeURIComponent(param) : param);
			    }
			  } else {
			    for (var i in param) {
			      var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
			      paramStr += this.urlEncode(param[i], k, encode);
			    }
			  }
			  return paramStr;
			},
			
		}
      

    }
	

</script>


<style scoped lang="less">

</style>
